#ifndef __ATL_PROCESS_H__
#define __ATL_PROCESS_H__
#include <cstdint.h>
#include "x86.h"
#include "fs.h"
#include <linked_list.h>
//#include "kstdio.h"
#define KERNEL_STACK_SIZE 2048

#ifndef FILETABLE_DEF
#define FILETABLE_DEF
typedef struct filetable {
	LLIST * freed_fds;
	int		fd_alloc;
	ILLIST *fd_table;
} filetable_t;
#endif

typedef struct process_start_params {
	uint32_t entry_point;
	uint32_t initial_stack_size;
	uint32_t max_stack_size;
	uint32_t initial_heap_size;
	uint32_t max_heap_size;
	uint32_t code_size;
	uint32_t image_base;
	//Results:
	uint32_t code_ptr;
	uint32_t base_ptr;
	uint32_t heap_ptr;
	uint32_t pid;
} process_start_params_t;

typedef struct process_info {
	uint32_t pid;
	uint32_t uid;
	uint32_t gid;
	uint32_t mask;
	uint32_t state;
	uint32_t priority;
	uint32_t errno;
	uint32_t exit_eip;
	uint32_t exit_esp;
	uint32_t exit_ebp;
	uint32_t eip;
	uint32_t esp;
	uint32_t ebp;
	struct process_info *parent;
	uint64_t start_time;
	void *code_start;
	void *entry_point;
	void *stack_start;
	void *stack_base;
	void *stack_limit;
	void *heap_start;
	void *heap_end;
	void *kernel_stack;
	struct vfs_node *root_directory;
	struct vfs_node *current_directory;
	filetable_t *fd_table;
	char name[128];
} process_info_t;

int start_task(process_info_t *t);

void select_task(process_info_t *t);

void setup_initial_process();

process_info_t *get_current_process();

void exit(int code);

void switch_to_usermode();

process_info_t * create_process(process_start_params_t *params);

#endif